home *** CD-ROM | disk | FTP | other *** search
/ Pocket PC Game Programming / Pocket PC Game Programming.iso / source.exe / CH15 / Project01 / GameLibrary.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-28  |  4.8 KB  |  154 lines

  1. //////////////////////////////////////////////////////////////////////
  2. // Pocket PC Game Programming
  3. //
  4. // CGameLibrary Header File
  5. //
  6. // This file includes the CGameLibrary class definition.
  7. //
  8. //////////////////////////////////////////////////////////////////////
  9.  
  10. #pragma once
  11.  
  12. #include "stdafx.h"
  13.  
  14. //primary windows functions
  15. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
  16. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  17.  
  18. //game library event functions
  19. extern "C" 
  20. {
  21.     BOOL GameInit(HINSTANCE hInst);
  22.     void GameStart(HWND hWnd);
  23.     void GameEnd();
  24.     void GameActivate(HWND hWnd);
  25.     void GameEvent();
  26.     void GamePaint(HWND hWnd);
  27.     void StylusDown(int x, int y);
  28.     void StylusMove(int x, int y);
  29.     void StylusUp(int x, int y);
  30.     
  31.     //*** New events for Chapter 11 ******************************
  32.     void ButtonPress(int iButtonID, POINT pt);
  33.     void ButtonRelease(int iButtonID, POINT pt);
  34.     //************************************************************
  35. }
  36.  
  37. //color struct used by drawing routines
  38. struct COLOR
  39. {
  40.     BYTE Red;
  41.     BYTE Green;
  42.     BYTE Blue;
  43. };
  44.  
  45. //support functions
  46. void MsgBox(LPTSTR szMessage);
  47.  
  48. ////////////////////////////////////////////////////////////
  49. // CGameLibrary
  50. // Primary class for the game library
  51. ////////////////////////////////////////////////////////////
  52. class CGameLibrary  
  53. {
  54. protected:
  55.     //pointer to the CGameLibrary object
  56.     static CGameLibrary *pGameLib;
  57.  
  58.     TCHAR szWindowClass[40];
  59.     TCHAR szTitle[40];
  60.     BOOL bHibernate;
  61.     BOOL bFullscreen;
  62.     WORD wProgramIcon;
  63.     int iFrameRate;
  64.  
  65.     //GDI-specific
  66.     HINSTANCE hInstance;
  67.     HWND hWindow;
  68.  
  69.     //GAPI-specific
  70.     unsigned char *GAPIVidMem;
  71.     BOOL bGAPIDisplay;
  72.     GXDisplayProperties gxDisplay;
  73.  
  74.     //*** New variable for Chapter 11 ****************************
  75.  
  76.     GXKeyList gxKeys;
  77.  
  78.     //************************************************************
  79.  
  80. public:
  81.     //construct/destruct methods
  82.     CGameLibrary(HINSTANCE hInst, LPTSTR szNewWindowClass);
  83.     virtual ~CGameLibrary();
  84.  
  85.     //primary game library methods
  86.     BOOL Initialize(int nCmdShow);
  87.     LRESULT EventHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  88.     void Error(LPTSTR szError);
  89.     void Shutdown();
  90.     int ScreenWidth() { return GetSystemMetrics(SM_CXSCREEN); };
  91.     int ScreenHeight() { return GetSystemMetrics(SM_CYSCREEN); };
  92.  
  93.     //added in Chapter 12 **************************************************************
  94.     void PrintText(HDC hdc, LPCTSTR strText, int x, int y, COLORREF color, int iBkMode);
  95.     void FatalError(LPTSTR lpStr);
  96.     LPWSTR GetPath(TCHAR *filename = _T(""));
  97.     //**********************************************************************************
  98.  
  99.     //program instance methods
  100.     HINSTANCE GetInstance() { return hInstance; };
  101.     void SetInstance(HINSTANCE hInst) { hInstance = hInst; };
  102.  
  103.     //program window methods
  104.     HWND GetWindow() { return hWindow; };
  105.     void SetWindow(HWND hWnd) { hWindow = hWnd; };
  106.  
  107.     //window title methods
  108.     LPTSTR GetTitle() { return szTitle; };
  109.     void SetTitle(LPTSTR szNewTitle) { wcscpy(szTitle, szNewTitle); };
  110.  
  111.     //hibernate setting methods
  112.     BOOL GetHibernate() { return bHibernate; };
  113.     void SetHibernate(BOOL bSet) { bHibernate = bSet; };
  114.  
  115.     //fullscreen setting methods
  116.     BOOL GetFullscreen() { return bFullscreen; };
  117.     void SetFullscreen(BOOL bSet) { bFullscreen = bSet; };
  118.  
  119.     //icon setting methods
  120.     WORD GetIcon() { return wProgramIcon; };
  121.     void SetIcon(WORD wIcon) { wProgramIcon = wIcon; }; 
  122.  
  123.     //frame rate methods
  124.     int GetFrameRate() { return iFrameRate; };
  125.     void SetFrameRate(int iFrames) { iFrameRate = 1000/iFrames; };
  126.  
  127.     //GAPI functions and methods
  128.     BOOL G_Enabled() { return bGAPIDisplay; };
  129.     void G_SetDisplay(BOOL bSet) { bGAPIDisplay = bSet; };
  130.     void G_BeginDraw();
  131.     void G_EndDraw();
  132.     int GetXPitch() { return gxDisplay.cbxPitch; };
  133.     int GetYPitch() { return gxDisplay.cbyPitch; };
  134.     int GetBitsPerPixel() { return gxDisplay.cBPP; };
  135.     BOOL IsScreenFormat565() { return (gxDisplay.ffFormat | kfDirect565); };
  136.     unsigned char *G_GetVidMem() { return GAPIVidMem; };
  137.     BOOL G_ClearScreen(COLOR color);
  138.     int G_DrawPixel16(unsigned char *VidMem, int X, int Y, COLOR color);
  139.     void G_DrawSolidRect(unsigned char *VidMem, int iLeft, int iTop, int iRight, int iBottom, COLOR color);
  140.  
  141.     //return the static Class object
  142.     static CGameLibrary *GetObj(void) { return pGameLib; };
  143.  
  144.     //grant MsgBox access to the class object
  145.     friend void MsgBox(LPTSTR szMessage);
  146.  
  147.  
  148. };
  149.  
  150. //global CGameLibrary pointer
  151. inline CGameLibrary *GameLib() { return CGameLibrary::GetObj(); };
  152.  
  153.  
  154.